// pages/user/teacherDetail/teacherDetail.js
//获取应用实例
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: 0,
        detail: null,
        isIphoneX: app.globalData.isIphoneX,
        navigation: {
            title: "教师详情", //页面标题
            isLeftShow: true, //是否显示左箭头
            color: '#fff' //字体颜色
        },
        isAttention: false, //关注

        curriculum: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.data.id = options.id;
        this.onPullDownRefresh();
    },



    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.loadDetail().finally(() => {
            wx.stopPullDownRefresh();
        });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        const image = "";
        return {
            imageUrl: image,
            path: this.route + `?id=${this.data.id}`
        }
    },

    // 关注
    attentionTap: function() {
        wx.http.get('/api/curriculum.Lecturer/follow', {
            lecturer_id: this.data.id
        }, {
            showLoading: true
        }).then((res) => {
            const is_follow = !this.data.detail.is_follow;
            const follow_num = is_follow ? this.data.detail.follow_num + 1 : this.data.detail.follow_num - 1;
            this.setData({
                'detail.is_follow': is_follow,
                'detail.follow_num': follow_num
            });
        });
    },

    // 加载商品详情
    loadDetail: function() {
        return wx.http.get('api/curriculum.Lecturer/details', {
            lecturer_id: this.data.id
        }).then((res) => {
            this.setData({
                detail: res.data.data.lecturer_info,
                curriculum: res.data.data.lecturer_curriculum.data,
            });
        }, (err) => {
            console.warn("api/curriculum.Lecturer/details", err)
        });
    },
});
